package com.skynet.supervision.utils;

import cn.hutool.core.util.ObjectUtil;
import com.skynet.supervision.aop.uac.beans.UACTokenInfo;
import com.skynet.supervision.constants.SysConstants;

public class TokenCacheUtils {
    public static final String SEPARATOR = ",";

    private static String getCacheName() {
        return SysConstants.SYS_AUTH_CACHE;
    }

    private static String getCacheKey(String configKey) {
        return SysConstants.SYS_AUTH_CACHE_KEY + configKey;
    }

    public static void removeAuthCache(String tokenId) {
        CacheUtils.remove(getCacheName(), getCacheKey(tokenId));
    }

    public static void setAuthCache(String tokenId, UACTokenInfo tokenInfo) {
        CacheUtils.put(getCacheName(), getCacheKey(tokenId), tokenInfo);
    }

    public static UACTokenInfo getAuthCache(String tokenId) {
        Object cacheObj = CacheUtils.get(getCacheName(), getCacheKey(tokenId));
        if (ObjectUtil.isNotNull(cacheObj)) {
            return ObjectUtils.cast(cacheObj);
        }
        return null;
    }

    public static void clearAuthCache() {
        CacheUtils.removeAll(getCacheName());
    }
}
